<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@include file="/comm/mytags.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title>后台管理系统</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="keywords" content="后台管理系统">
    <link rel="shortcut icon" href="${ctx}/static/img/favicon.ico">
    <link rel="stylesheet" href="${ctx}/static/layui_v2/css/layui.css">

    <script src="${ctx}/static/layui_v2/layui.js"></script>

</head>
<body class="childrenBody" style="font-size: 12px;margin: 10px 10px 0;">
<form class="layui-form layui-form-pane">
    <input id="userId" name="userId" type="hidden" value="${user.userId}">
    <div class="layui-form-item">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" name="userName" lay-verify="required|userName" maxlength="20" value="${user.userName}" placeholder="请输入用户名">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">手机号码</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" name="tel" lay-verify="required|tel" maxlength="11" value="${user.tel}" placeholder="请输入用户手机号码">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">剩余博饼次数</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" name="dayJoinCount" lay-verify="required|dayJoinCount" maxlength="10" value="${user.dayJoinCount}" placeholder="请输入用户剩余博饼次数">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">拥有积分</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" name="credits" lay-verify="required|credits" maxlength="10" value="${user.credits}" placeholder="请输入用户积分">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">总博饼次数</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" name="totalJoinCount" lay-verify="required|totalJoinCount" maxlength="10" value="${user.totalJoinCount}" placeholder="请输入总博饼次数">
        </div>
    </div>
    <div class="layui-form-item" pane>
        <label class="layui-form-label">用户状态</label>
        <div class="layui-input-block">
                <input type="radio" name="userStatus" value="1" title="有效"   <c:if test="${user.userStatus ==1}">checked</c:if>/>
                <input type="radio" name="userStatus" value="0" title="失效"   <c:if test="${user.userStatus ==0 }">checked</c:if>/>
        </div>
    </div>
    <div class="layui-form-item" style="text-align: center;">
            <button class="layui-btn" lay-submit="" lay-filter="saveUser">保存</button>
            <button type="layui-btn" id="cancle" class="layui-btn layui-btn-primary">取消</button>
    </div>
</form>
<script type="text/javascript">
    layui.config({
        base : "${ctx}/static/js/"
    }).use(['form','layer','jquery','common'],function(){
        var $ = layui.$,
                form = layui.form,
                common = layui.common,
                layer = parent.layer === undefined ? layui.layer : parent.layer;

        /**表单验证*/
        form.verify({
            userName: function(value, item){
                //验证用户名
                if(value.trim().length > 20 || value.trim().length < 2){
                    return "用户名必须2到20个字符之间";
                }
            },
            tel:function (value, item) {
                if(!(/^1[34578]\d{9}$/.test(value))){
                    return "请输入正确手机号"
                }
            },
            dayJoinCount:function (value, item) {
                if(isNaN(value)){
                    return "请输入数字";
                }
            },
            credits:function (value, item) {
                if(isNaN(value)){
                    return "请输入数字";
                }
            },
            totalJoinCount:function (value, item) {
                if(isNaN(value)){
                    return "请输入数字";
                }
            },
        });

        /**保存*/
        form.on("submit(saveUser)",function(data){
            var pageFlag = $("#pageFlag").val();
            var userSaveLoading = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
            //登陆验证
            $.ajax({
                url : '${ctx}/userUpdate',
                type : 'post',
                async: false,
                data : data.field,
                success : function(data) {
                    if(data.code == 0){
                        top.layer.close(userSaveLoading);
                        common.cmsLaySucMsg("保存成功");
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭                        //刷新父页面
                        parent.location.reload();
                    }else{
                        top.layer.close(userSaveLoading);
                        common.cmsLayErrorMsg(data.msg);
                    }
                },error:function(data){
                    top.layer.close(index);

                }
            });
            return false;
        });
        //取消
        $("#cancle").click(function(){
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            parent.layer.close(index); //再执行关闭
        });

    });

</script>
</body>
</html>